package com.source.chart.controller;

import com.source.chart.VO.PoultrySalesChart;
import com.source.chart.VO.PoultrySalesCountChart;
import com.source.chart.VO.PoultrySalesVO;
import com.source.chart.VO.PoultrySpeciesCountChart;
import com.source.chart.service.PoultrySalesChartService;
import com.source.utils.CommonResult;
import com.source.utils.ResultEnum;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;

@Api(tags = "禽类贴标销售图表集")
@CrossOrigin
@RestController
@RequestMapping(value = "/poultrySales")
public class PoultrySalesController {


    @Autowired
    private PoultrySalesChartService poultrySalesChartService;

    @ApiOperation(value = "查找销售去向 by市场")
    @GetMapping("/findAll/chart/by/house")
    public CommonResult findAllSales(int house_id) {
        List<PoultrySalesVO> vos = poultrySalesChartService.findAllSales(house_id);
//        System.out.println(vos.get(0).toString());
        return new CommonResult(ResultEnum.SUCCESS, vos);
    }

    @ApiOperation(value = "按年制返回该市场父级禽类销量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "父级禽类id", required = true),
            @ApiImplicitParam(name = "houseId", value = "市场id", required = true)
    })
    @GetMapping("/findCountOfParent/by/year")
    public CommonResult findCountOfParentInYear(String parentId, String houseId) {
        Map<String, BigInteger> map =  poultrySalesChartService.findSalesInYears(parentId, houseId);
        return new CommonResult(ResultEnum.SUCCESS, map);
    }

//    @ApiOperation(value = "按年制、根据市场id返回该市场父级禽类销量")
//    @GetMapping("/findCountOfParent/{houseId}")
//    public CommonResult findCountOfParentInYear(@PathVariable String houseId){
//        HashMap<String, Long> res = new HashMap<String, Long>();
//        res = poultrySalesChartService.findCountOfParentInYear(houseId);
//        return new CommonResult(ResultEnum.SUCCESS, res);
//    }

    @ApiOperation(value = "按年制返回所有市场父级禽类销量")
    @GetMapping("/findCountOfParent/{houseId}")
    public CommonResult findCountOfParent(@PathVariable @ApiParam("屠宰场id") String houseId){
        PoultrySalesChart poultrySalesChart = poultrySalesChartService.findCountOfParentByHouseId(houseId);
        if (poultrySalesChart==null){
            return CommonResult.error("查询结果为空");
        }else {
            return CommonResult.success("查询成功").data(poultrySalesChart);
        }
    }

    @ApiOperation(value = "根据屠宰场id查询当年的禽类销售数量")
    @GetMapping("/poultrySpeciesOfYear/{houseId}")
    public CommonResult findPoultrySpeciesCountOfYear(@PathVariable("houseId") String houseId){
        List<PoultrySpeciesCountChart> poultryCategoryCount = poultrySalesChartService.selectPoultryCategoryCountOfYear(houseId);
        if (poultryCategoryCount.isEmpty()){
            return CommonResult.error("查询结果为空");
        }else {
            return CommonResult.success("查询成功").data(poultryCategoryCount);
        }
    }

    @ApiOperation(value = "根据屠宰场id查询所有的禽类销售数量")
    @GetMapping("/poultrySpeciesOfAll/{houseId}")
    public CommonResult findPoultrySpeciesCountOfAll(@PathVariable("houseId") String houseId){
        List<PoultrySpeciesCountChart> poultryCategoryCount = poultrySalesChartService.selectPoultryCategoryCountOfAll(houseId);
        if (poultryCategoryCount.isEmpty()){
            return CommonResult.error("查询结果为空");
        }else {
            return CommonResult.success("查询成功").data(poultryCategoryCount);
        }
    }

    @ApiOperation(value = "根据屠宰场id查询当年每一个月的禽类销售数量")
    @GetMapping("/poultryCountOfMonth/{houseId}")
    public CommonResult findPoultrySalesCountOfMonth(@PathVariable("houseId")@ApiParam("屠宰场id") String houseId){
        PoultrySalesCountChart poultryCateCountOfMoth = poultrySalesChartService.getPoultryCateCountOfMoth(houseId);
        if (poultryCateCountOfMoth==null){
            return CommonResult.error("查询结果为空");
        }else {
            return CommonResult.success("查询成功").data(poultryCateCountOfMoth);
        }
    }



}
